home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / What's New? / Development Kits / Apple Game Sprockets DR1 / Examples / SoundSprocketTest / TS3Events.c next >
Encoding:
C/C++ Source or Header  |  1996-04-24  |  6.1 KB  |  312 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    File:        TS3Events.c
  3.  *    Author:        Dan Venolia
  4.  *
  5.  *    Contents:    Handles the events.
  6.  *
  7.  *    Copyright © 1996 Apple Computer, Inc.
  8.  */
  9.  
  10. #include <assert.h>
  11.  
  12. #include <AppleEvents.h>
  13. #include <Events.h>
  14. #include <ToolUtils.h>
  15. #include <Types.h>
  16. #include <Windows.h>
  17.  
  18. #include "TS3Events.h"
  19. #include "TS3Main.h"
  20. #include "TS3Menu.h"
  21. #include "TS3Window.h"
  22.  
  23.  
  24. static void Events_MouseDown(
  25.     const EventRecord*        inEvent);
  26.  
  27. static void Events_KeyDown(
  28.     const EventRecord*        inEvent);
  29.  
  30. static void Events_AutoKey(
  31.     const EventRecord*        inEvent);
  32.  
  33. static void Events_Update(
  34.     const EventRecord*        inEvent);
  35.  
  36. static void Events_Activate(
  37.     const EventRecord*        inEvent);
  38.  
  39. static void Events_OS(
  40.     const EventRecord*        inEvent);
  41.  
  42. static void Events_HighLevel(
  43.     const EventRecord*        inEvent);
  44.  
  45.  
  46. /* =============================================================================
  47.  *        Events_Init (external)
  48.  *
  49.  *    Initializes the events stuff.
  50.  * ========================================================================== */
  51. void Events_Init(
  52.     void)
  53. {
  54.     FlushEvents(everyEvent, 0);
  55. }
  56.  
  57.  
  58. /* =============================================================================
  59.  *        Events_Exit (external)
  60.  *
  61.  *    Prepares for exit.
  62.  * ========================================================================== */
  63. void Events_Exit(
  64.     void)
  65. {
  66. }
  67.  
  68.  
  69. /* =============================================================================
  70.  *        Events_Process (external)
  71.  *
  72.  *    Processes any pending events.
  73.  * ========================================================================== */
  74. void Events_Process(
  75.     void)
  76. {
  77.     UInt32                    sleep;
  78.     EventRecord                ev;
  79.     Boolean                    consumed;
  80.     
  81.     Window_GetSleep(FrontWindow(), &sleep);
  82.     
  83.     while (WaitNextEvent(everyEvent, &ev, sleep, NULL))
  84.     {
  85.         Window_ConsumeEvent(FrontWindow(), &ev, &consumed);
  86.         
  87.         if (!consumed)
  88.         {
  89.             switch (ev.what)
  90.             {
  91.                 case mouseDown:
  92.                     Events_MouseDown(&ev);
  93.                 break;
  94.                 
  95.                 case keyDown:
  96.                     Events_KeyDown(&ev);
  97.                 break;
  98.                 
  99.                 case autoKey:
  100.                     Events_AutoKey(&ev);
  101.                 break;
  102.                 
  103.                 case updateEvt:
  104.                     Events_Update(&ev);
  105.                 break;
  106.                 
  107.                 case activateEvt:
  108.                     Events_Activate(&ev);
  109.                 break;
  110.                 
  111.                 case osEvt:
  112.                     Events_OS(&ev);
  113.                 break;
  114.                 
  115.                 case kHighLevelEvent:
  116.                     Events_HighLevel(&ev);
  117.                 break;
  118.             }
  119.         }
  120.     }
  121.     
  122.     // Pass on a NULL event when WaitNextEvent returns false to keep dialog caret blinking
  123.     ev.what = nullEvent;
  124.     Window_ConsumeEvent(FrontWindow(), &ev, &consumed);
  125. }
  126.  
  127.  
  128. /* =============================================================================
  129.  *        Events_MouseDown (internal)
  130.  *
  131.  *    Processes a mouse-down event.
  132.  * ========================================================================== */
  133. void Events_MouseDown(
  134.     const EventRecord*        inEvent)
  135. {
  136.     short                     part;
  137.     WindowPtr                wind;
  138.     long                    menu;
  139.     
  140.     assert(inEvent != NULL);
  141.     
  142.     part = FindWindow(inEvent->where, &wind);
  143.     
  144.     switch (part)
  145.     {
  146.         case inMenuBar:
  147.             menu = MenuSelect(inEvent->where);
  148.             Menu_Select(HiWord(menu), LoWord(menu));
  149.         break;
  150.             
  151.         case inSysWindow:
  152.             SystemClick(inEvent, wind);
  153.         break;
  154.             
  155.         case inDrag:
  156.             DragWindow(wind, inEvent->where, &qd.screenBits.bounds);
  157.         break;
  158.             
  159.         case inGoAway:
  160.             Main_LastRoundup();
  161.         break;
  162.                 
  163.         case inContent:
  164.             if (wind == FrontWindow())
  165.             {
  166.                 Window_MouseDown(wind, inEvent->where);
  167.             }
  168.             else
  169.             {
  170.                 SelectWindow(wind);
  171.             }
  172.         break;
  173.             
  174.         case inGrow:
  175.             // nothing yet...
  176.         break;
  177.     }
  178. }
  179.  
  180.  
  181. /* =============================================================================
  182.  *        Events_KeyDown (internal)
  183.  *
  184.  *    Processes a key-down event.
  185.  * ========================================================================== */
  186. void Events_KeyDown(
  187.     const EventRecord*        inEvent)
  188. {
  189.     unsigned long            ch;
  190.     unsigned long            cap;
  191.     long                    menu;
  192.     
  193.     assert(inEvent != NULL);
  194.     
  195.     ch = inEvent->message & charCodeMask;
  196.     cap = (inEvent->message & keyCodeMask) >> 8;
  197.     
  198.     if ((inEvent->modifiers & cmdKey) == 0)
  199.     {
  200.         Window_KeyDown(FrontWindow(), ch, cap, inEvent->modifiers, false);
  201.     }
  202.     else
  203.     {
  204.         menu = MenuKey(ch);
  205.         Menu_Select(HiWord(menu), LoWord(menu));
  206.     }
  207. }
  208.  
  209.  
  210. /* =============================================================================
  211.  *        Events_AutoKey (internal)
  212.  *
  213.  *    Processes an auto-key event.
  214.  * ========================================================================== */
  215. void Events_AutoKey(
  216.     const EventRecord*        inEvent)
  217. {
  218.     unsigned long            ch;
  219.     unsigned long            cap;
  220.     
  221.     assert(inEvent != NULL);
  222.     
  223.     ch = inEvent->message & charCodeMask;
  224.     cap = (inEvent->message & keyCodeMask) >> 8;
  225.     
  226.     if ((inEvent->modifiers & cmdKey) == 0)
  227.     {
  228.         Window_KeyDown(FrontWindow(), ch, cap, inEvent->modifiers, true);
  229.     }
  230. }
  231.  
  232.  
  233. /* =============================================================================
  234.  *        Events_Update (internal)
  235.  *
  236.  *    Processes an update event.
  237.  * ========================================================================== */
  238. void Events_Update(
  239.     const EventRecord*        inEvent)
  240. {
  241.     WindowPtr                wind;
  242.     
  243.     assert(inEvent != NULL);
  244.     
  245.     wind = (WindowPtr) inEvent->message;
  246.     
  247.     SetPort(wind);
  248.     BeginUpdate(wind);
  249.     Window_Update(wind);
  250.     EndUpdate(wind);
  251. }
  252.  
  253.  
  254. /* =============================================================================
  255.  *        Events_Activate (internal)
  256.  *
  257.  *    Processes an activate event.
  258.  * ========================================================================== */
  259. void Events_Activate(
  260.     const EventRecord*        inEvent)
  261. {
  262.     WindowPtr                wind;
  263.     
  264.     assert(inEvent != NULL);
  265.     
  266.     wind = (WindowPtr) inEvent->message;
  267.     
  268.     if (inEvent->modifiers & activeFlag)
  269.     {
  270.         Window_Activate(wind);
  271.     }
  272.     else
  273.     {
  274.         Window_Deactivate(wind);
  275.     }
  276. }
  277.  
  278.  
  279. /* =============================================================================
  280.  *        Events_OS (internal)
  281.  *
  282.  *    Processes an OS event.
  283.  * ========================================================================== */
  284. void Events_OS(
  285.     const EventRecord*        inEvent)
  286. {
  287.     assert(inEvent != NULL);
  288.     
  289.     if ((inEvent->message >> 24) & 0xFF == suspendResumeMessage)
  290.     {
  291.         // nothing yet...
  292.     }
  293. }
  294.  
  295.  
  296. /* =============================================================================
  297.  *        Events_HighLevel (internal)
  298.  *
  299.  *    Processes a high-level event.
  300.  * ========================================================================== */
  301. void Events_HighLevel(
  302.     const EventRecord*        inEvent)
  303. {
  304.     assert(inEvent != NULL);
  305.     
  306.     AEProcessAppleEvent(inEvent);
  307. }
  308.  
  309.  
  310.  
  311.  
  312.